home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vim_src.zip / DEBUG.H < prev    next >
C/C++ Source or Header  |  1993-01-12  |  1KB  |  45 lines

  1. /*
  2.  * debug.h -- my debug header for just any program.
  3.  * use:
  4.  * place the statement OPENDEBUG; inside main.
  5.  * nothing will happen, unless you compile the source with
  6.  * -DDEBUG="/tmp/programdebug"
  7.  * 
  8.  * jw. 13.4.91.
  9.  */
  10. #ifndef FILE
  11. # include <stdio.h>
  12. #endif
  13.  
  14. #ifdef DEBUG
  15. #    define debug(x) {fprintf(debugfp,x);fflush(debugfp);}
  16. #    define debug1(x,a) {fprintf(debugfp,x,a);fflush(debugfp);}
  17. #    define debug2(x,a,b) {fprintf(debugfp,x,a,b);fflush(debugfp);}
  18. #    define debug3(x,a,b,c) {fprintf(debugfp,x,a,b,c);fflush(debugfp);}
  19. #    define OPENDEBUG(file)\
  20.     if ((debugfp = fopen(file,"w")) == NULL)\
  21.     {    debugfp = stderr;\
  22.         debug1("OPENDEBUG: sorry, cannot open '%s'\n", file);\
  23.         debug("           beware, using stderr!\n");\
  24.         sleep(3);\
  25.     }
  26. #else
  27. #    define debug(x)
  28. #    define debug1(x,a)
  29. #    define debug2(x,a,b)
  30. #    define debug3(x,a,b,c)
  31. #    define OPENDEBUG
  32. #endif
  33.  
  34. #undef NOASSERT
  35.  
  36. #ifndef NOASSERT
  37. # if defined(__STDC__)
  38. #  define ASSERT(lousy_cpp) {if (!(lousy_cpp)) {debug2("ASSERT("#lousy_cpp")ion failed file %s line %d\n", __FILE__, __LINE__);abort();}}
  39. # else
  40. #  define ASSERT(lousy_cpp) {if (!(lousy_cpp)) {debug2("ASSERT(lousy_cpp)ion failed file %s line %d\n", __FILE__, __LINE__);abort();}}
  41. # endif
  42. #else
  43. # define ASSERT(lousy_cpp) {;}
  44. #endif
  45.